package edu.jd.movieplatform.c_admin.movie.impl;

import edu.jd.movieplatform.c_admin.movie.AddDto;
import edu.jd.movieplatform.c_admin.movie.ScreenDto;
import edu.jd.movieplatform.c_admin.movie.ScreenService;
import edu.jd.movieplatform.c_admin.movie.UpdDto;
import edu.jd.movieplatform.c_admin.movie.dao.C_adminScreenDao;
import edu.jd.movieplatform.common.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @descriptions:
 * @data: 2021/7/16 17:10
 */
@Service
@Transactional
public class ScreenServiceImpl implements ScreenService {
    @Resource
    private C_adminScreenDao dao;

    @Override
    public Map<String, Object> getScreenList(ScreenDto dto) {
        return Utils.getPage(dto, () -> dao.findScreenList(dto));
    }

    @Override
    public void addScreen(AddDto addDto) {
        System.out.println(addDto.getMov_name());
        System.out.println(addDto.getCnm_name());
        System.out.println(addDto.getCnm_hall_id());
        System.out.println(addDto.getScreen_time());
        ScreenDto dto = new ScreenDto();

        dto.setMov_id(dao.getMovidByMovName(addDto.getMov_name()));
        dto.setCnm_id(dao.getCnmIdByCnmName(addDto.getCnm_name()));
        dto.setCnm_hall_id(addDto.getCnm_hall_id());
        dto.setScreen_time(addDto.getScreen_time());
        dto.setPrice(addDto.getPrice());
        dao.insertScreen(dto);
    }

    @Override
    public List<Integer> getCinemaIdList(String name) {
        return dao.findCinemaHallIdByName(name);
    }

    @Override
    public void updScreen(UpdDto dto) {
        dto.setMov_id(dao.getMovidByMovName(dto.getMov_name()));
        dao.updScreen(dto);
    }

    @Override
    public void delScreen(Integer id) {
        dao.delScreen(id);
    }
}
